package com.lzy.system.organization.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzy.conf.JSONResult;
import com.lzy.system.organization.dto.SysRoleNavAddDTO;
import com.lzy.system.organization.service.ISysRoleNavService;
import com.lzy.utils.ValidList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色对应导航 前端控制器
 * </p>
 *
 * @author lcc
 * @since 2023-12-06
 */
@RestController
@RequestMapping("/organization/sysRoleNav")
@Api(tags = "角色对应导航")
public class SysRoleNavController {
    ISysRoleNavService iSysRoleNavService;

    @Autowired
    public SysRoleNavController(ISysRoleNavService iSysRoleNavService) {
        this.iSysRoleNavService = iSysRoleNavService;
    }

    @ApiOperation("根据角色id查询导航")
    @RequestMapping(value = "queryByRoleId/{id}", method = RequestMethod.GET)
    public JSONResult queryByResId(@ApiParam("角色id") @PathVariable(value = "id", required = true) Integer id) throws Exception {
        List list = iSysRoleNavService.list(new QueryWrapper() {{
            eq("role_id", id);
        }});
        return JSONResult.ok(list);
    }

    @ApiOperation("保存角色对应导航")
    @RequestMapping(value = "save/{roleid}", method = RequestMethod.POST)
    public JSONResult save(
            @ApiParam("角色id") @PathVariable Integer roleid,
            @ApiParam("角色对应导航") @RequestBody() @Validated ValidList<SysRoleNavAddDTO> list
    ) throws Exception {
        iSysRoleNavService.save(roleid,list);
        return JSONResult.ok(list);
    }
}
